/* 
  折叠tokens,把#和/之间的内容进行折叠
*/
export default function nestTokens(tokens) {
  let nestedTokens = []
  // 创建一个栈
  let sections = []
  // 创建一个指针 收集器
  let collector = nestedTokens

  for (let i = 0; i < tokens.length; i++) {
    let token = tokens[i]

    switch (token[0]) {
      case '#':
        collector.push(token)
        sections.push(token)
        collector = token[2] = []
        break;
      case '/':
        sections.pop()
        collector = sections.length > 0 ? sections[sections.length - 1][2] : nestedTokens
        break;
      default:
        collector.push(token)

    }
  }

  return nestedTokens
}